﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test
{
    public partial class Form1 : DevExpress.XtraEditors.XtraForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnClick_Click(object sender, EventArgs e)
        {
            string fileName = string.Empty;
            string pathFile = XMLInputFile.CreateXMLInputFile(out fileName, null);
            //track = -1;
            if (!XMLInputFile.WriteInputValueBase(pathFile))
            {
                MessageBox.Show(String.Format("Chương trình xảy ra lỗi trong quá trình tạo dữ liệu ban đầu."));
                //break;
            }
            string exeFile = System.IO.Directory.GetCurrentDirectory() + @"\engine\fet-cl";
            string inputFile = String.Format(@"{0}\data\input\{1}.fet", System.IO.Directory.GetCurrentDirectory(), fileName);
            string outputDir = System.IO.Directory.GetCurrentDirectory() + @"\engine\result\";

            //int time = int.Parse(Program.Constraint["TimeProcessing"].ToString());

            string command = string.Format(@"{0} --inputfile={1} --outputdir={2} ", exeFile, inputFile, outputDir);
            //track = 4;
            ProcessStartInfo ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
            ProcessInfo.CreateNoWindow = true;
            ProcessInfo.UseShellExecute = false;
            //ProcessInfo.WindowStyle = ProcessWindowStyle.Hidden;

            Process Process = Process.Start(ProcessInfo);
            Process.WaitForExit();
            if (System.IO.Directory.Exists(outputDir))
            {
                //track = 6;
                Program.pathOutputFile = String.Format(@"{0}timetables\{1}\{1}_activities.xml", outputDir, fileName);

                if (!System.IO.File.Exists(Program.pathOutputFile))
                    Program.pathOutputFile = String.Format(@"{0}timetables\{1}-highest\{1}_activities.xml", outputDir, fileName);
                //track = 7;
                Process.Close();

                //track = 8;
                ////Save          
                //activities = Functions.Save(activities, Program.pathOutputFile);
                ////Xóa bỏ các khoảng trống
                //Functions.Repair();
                ////Functions.RepairX2();
                ////Đồng bộ hóa sự kiện
                //Functions.Synchronous(activities);
            }
        }
    }
}
